package com.example.design01.controller;


import com.example.design01.Bean.AdminBean;
import com.example.design01.Bean.UserBean;
import com.example.design01.Service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

@Controller
public class AdminController {

    @Autowired
    private AdminService adminService;

    //    admin登陆跳转
    @RequestMapping("/toLoginAdmin")
    public String toLoginAdmin() {
        return "loginAdmin";
    }

    @RequestMapping("/loginA")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model, HttpSession session){
        AdminBean adminBean = adminService.checkUser(username, password);
        if (adminBean != null) {
            session.setAttribute("LoginUser", username);
            return "redirect:/checkAll";
        } else {
            model.addAttribute("msg", "输入有误请重新输入");
            return "loginAdmin";
        }
    }


}
